From 53796dcf757a63a4956c500868872dddf256d302 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Mon, 19 Dec 2022 18:29:31 +0100
Subject: [PATCH] change the package disable path

---
 README.md  |  9 +++++----
 ckms       | 19 +++++++++++++------
 ckms.8.scd |  7 ++++---
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index 109b3bf..0937e6e 100644
--- a/README.md
+++ b/README.md
@@ -56,10 +56,11 @@ is installed into the state directory with `add`, so you no longer have to
 worry about it. You can still specify `-c` or `--modconf` manually if you
 wish to override it for some reason.
 
-It is possible to disable a module for a specific kernel version. This is done
-by creating a file named the same as the kernel version in the `ckms-disable`
-directory within the source tree of the module. If this is done, `ckms` will
-not allow you to build the module, and it will show as `disabled` in `status`.
+It is possible to disable a module for a specific kernel version. A module is
+disabled if the `ckms-disable` directory exists in the kernel module directory,
+containing `packagename`, it itself containing `packageversion`. If this is done,
+`ckms` will not allow you to build the module, and it will show as `disabled` in
+`status`.
 
 If disabled after it is built, it will show as `built+disabled` in `status`
 and it will not be installable. If disabled after it is installed, it will
diff --git a/ckms b/ckms
index 0c7727e..c3c1d7f 100755
--- a/ckms
+++ b/ckms
@@ -302,10 +302,6 @@ def read_package(pkgpath, by_name = False, check_source = True, guess_ver = Fals
         srcp = pkgpath / "source"
         if not srcp.is_dir():
             raise CkmsError(f"package source in '{pkgpath}' does not exist")
-        if (srcp / "ckms-disable" / opt_kernver).is_file():
-            raise CkmsError(
-                f"package in '{pkgpath}' disabled for kernel '{opt_kernver}'"
-            )
 
     pkgconf = opt_pkgconf
     if not pkgconf:
@@ -332,7 +328,17 @@ def read_package(pkgpath, by_name = False, check_source = True, guess_ver = Fals
     gen["ckms_statedir"] = str(opt_statedir)
     gen["ckms_destdir"] = str(opt_destdir)
 
-    return Package(gen["name"], gen["version"], pkgpath, pkgconf, mcfg)
+    pnm = gen["name"]
+    pvr = gen["version"]
+
+    if check_source and by_name:
+        cdp = kern_path / opt_kernver / "ckms-disable"
+        if (cdp / pnm / pvr).is_file():
+            raise CkmsError(
+                f"package '{pnm}={pvr}' disabled for kernel '{opt_kernver}'"
+            )
+
+    return Package(pnm, pvr, pkgpath, pkgconf, mcfg)
 
 def do_add(cmd):
     check_has_action(cmd)
@@ -657,7 +663,8 @@ def do_status(cmd, pretty = True):
                 # if not built and source does not exist, exclude from status
                 continue
             # handle disabled packages
-            if (v / "source/ckms-disable" / opt_kernver).is_file():
+            cdp = kern_path / opt_kernver / "ckms-disable"
+            if (cdp / pkgname / version).is_file():
                 if state == "added":
                     state = "disabled"
                 elif state == "built":
diff --git a/ckms.8.scd b/ckms.8.scd
index dc48abc..878d0f9 100644
--- a/ckms.8.scd
+++ b/ckms.8.scd
@@ -170,9 +170,10 @@ The following states are recognized and valid.
 	from being built. This is mostly useful when a kernel is managing specific
 	modules on its own, and CKMS would only get in the way.
 
-	A package can be disabled for a kernel by creating a file with the same
-	name as the kernel version in the _ckms-disable_ directory located inside
-	the package's source tree.
+	A package can be disabled for a kernel by creating a file called the same
+	as the package version in a directory called the same as the package name
+	inside the _ckms-disable_ directory located inside the module directory,
+	for example _/lib/modules/4.20.69-0-generic/ckms-disable/zfs/2.0.5_.
 
 *built+disabled*
 	This is the state the package will have when it has been built for the
-- 
2.38.1

